]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
blur-effect: Floor downscaled frambuffer sizes
authorJonas Dreßler <verdre@v0yd.nl>
Mon, 10 Feb 2020 14:22:33 +0000 (15:22 +0100)
committerGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Wed, 12 Feb 2020 14:02:28 +0000 (14:02 +0000)
Floor the downscaled size of the new framebuffer to make sure we don't
initialize a framebuffer with a floating point value that might be
interpreted wrong by `cogl_texture_2d_new_with_size` and end up with a
slightly wrong aspect ratio of the framebuffer.

This fixes situations where the widths or heights of downscaled
framebuffers sometimes miss some pixels at the border.

While at it, remove the `downscale_factor` argument from
`setup_projection_matrix` since that function doesn't need the initial
size of the actor anyway.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/991

src/shell-blur-effect.c

index 7f1be6b1dfc8473aa6e86d084c06035d11098e4e..e40bb542a29191943934a58f0b860ee9645e6e26 100644 (file)
@@ -323,21 +323,18 @@ update_brightness_uniform (ShellBlurEffect *self)
 static void
 setup_projection_matrix (CoglFramebuffer *framebuffer,
                          float            width,
-                         float            height,
-                         float            downscale_factor)
+                         float            height)
 {
   CoglMatrix projection;
-  float downscaled_width = width / downscale_factor;
-  float downscaled_height = height / downscale_factor;
 
   cogl_matrix_init_identity (&projection);
   cogl_matrix_scale (&projection,
-                     2.0 / downscaled_width,
-                     -2.0 / downscaled_height,
+                     2.0 / width,
+                     -2.0 / height,
                      1.f);
   cogl_matrix_translate (&projection,
-                         -downscaled_width / 2.0,
-                         -downscaled_height / 2.0,
+                         -width / 2.0,
+                         -height / 2.0,
                          0);
 
   cogl_framebuffer_set_projection_matrix (framebuffer, &projection);
@@ -355,10 +352,10 @@ update_fbo (FramebufferData *data,
   g_clear_pointer (&data->texture, cogl_object_unref);
   g_clear_pointer (&data->framebuffer, cogl_object_unref);
 
-  data->texture =
-    cogl_texture_2d_new_with_size (ctx,
-                                   width / downscale_factor,
-                                   height / downscale_factor);
+  float new_width = floorf (width / downscale_factor);
+  float new_height = floorf (height / downscale_factor);
+
+  data->texture = cogl_texture_2d_new_with_size (ctx, new_width, new_height);
   if (!data->texture)
     return FALSE;
 
@@ -371,7 +368,7 @@ update_fbo (FramebufferData *data,
       return FALSE;
     }
 
-  setup_projection_matrix (data->framebuffer, width, height, downscale_factor);
+  setup_projection_matrix (data->framebuffer, new_width, new_height);
 
   return TRUE;
 }